package com.example.demo;

import java.util.Scanner;

public class ScoreManagerSimple {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int studentNum;
        // 1. 输入班级人数（确保正整数）
        System.out.println("学生成绩管理程序");
        System.out.println("-----------------");
        System.out.print("请输入班级人数：");
        studentNum = sc.nextInt();
        if (studentNum <= 0) {
            System.out.println("人数必须大于0，请重新输入！");
        }
        // 2. 录入学生成绩
        int[] scores = new int[studentNum];
        for (int i = 0; i < studentNum; i++) {
            System.out.print("请输入第" + (i + 1) + "位学生成绩：");
            scores[i] = sc.nextInt();
        }
        // 3. 打印成绩列表及等级
        System.out.println("-----------------");
        System.out.println("成绩列表：");
        for (int i = 0; i < scores.length; i++) {
            String level;
            if (scores[i] >= 90) {
                level = "优秀";
            } else if (scores[i] >= 80) {
                level = "良好";
            } else if (scores[i] >= 60) {
                level = "合格";
            } else {
                level = "不及格";
            }
            System.out.println((i + 1) + ". " + scores[i] + " - " + level);
        }
        // 4. 统计分析并输出结果
        int sum = 0;
        int max = scores[0];
        int excellentCount = 0;
        for (int score : scores) {
            sum += score;
            if (score > max) {
                max = score;
            }
            if (score >= 90) {
                excellentCount++;
            }
        }
        double avg = (double) sum / scores.length;
        System.out.println("-----------------");
        System.out.println("统计结果：");
        System.out.println("平均分：" + avg);
        System.out.println("最高分：" + max);
        System.out.println("优秀人数：" + excellentCount);
        // 5. 继续查询功能
        do {
            System.out.println("-----------------");
            System.out.print("是否继续查询？(1-是/0-否)");
            int choice = sc.nextInt();
            if (choice == 0) {
                System.out.println("程序结束，欢迎下次使用！");
                break;
            } else if (choice != 1) {
                System.out.println("输入错误，请重新选择！");
                continue;
            }
            // 重复输出统计结果
            System.out.println("-----------------");
            System.out.println("统计结果：");
            System.out.println("平均分：" + avg);
            System.out.println("最高分：" + max);
            System.out.println("优秀人数：" + excellentCount);
        } while (true);
        sc.close();
    }
}